#!/usr/bin/env python3
"""
数据对排序功能演示
"""

import sys
from PyQt5.QtWidgets import QApplication, QMessageBox
from PyQt5.QtCore import QTimer
from ui.main_window import MainWindow

def demo_sorting_features():
    """演示排序功能"""
    app = QApplication(sys.argv)
    
    # 创建主窗口
    window = MainWindow()
    
    # 模拟一些测试数据对
    test_pairs = [
        {
            'base_name': 'iLinac-CM01:LLRF-01:triggerrf4_amp/phase', 
            'amp_dataset': {'path': '/Group_0/iLinac-CM01:LLRF-01:triggerrf4amp', 'shape': (30, 10000)}, 
            'phase_dataset': {'path': '/Group_0/iLinac-CM01:LLRF-01:triggerrf4phase', 'shape': (30, 10000)}
        },
        {
            'base_name': 'iLinac-CM01:LLRF-01:triggerrf5_amp/phase', 
            'amp_dataset': {'path': '/Group_0/iLinac-CM01:LLRF-01:triggerrf5amp', 'shape': (30, 10000)}, 
            'phase_dataset': {'path': '/Group_0/iLinac-CM01:LLRF-01:triggerrf5phase', 'shape': (30, 10000)}
        },
        {
            'base_name': 'iLinac-CM01:LLRF-01:triggerrf6_amp/phase', 
            'amp_dataset': {'path': '/Group_0/iLinac-CM01:LLRF-01:triggerrf6amp', 'shape': (30, 10000)}, 
            'phase_dataset': {'path': '/Group_0/iLinac-CM01:LLRF-01:triggerrf6phase', 'shape': (30, 10000)}
        },
        {
            'base_name': 'iLinac-CM01:LLRF-01:triggerrf7_amp/phase', 
            'amp_dataset': {'path': '/Group_0/iLinac-CM01:LLRF-01:triggerrf7amp', 'shape': (30, 10000)}, 
            'phase_dataset': {'path': '/Group_0/iLinac-CM01:LLRF-01:triggerrf7phase', 'shape': (30, 10000)}
        },
    ]
    
    # 更新数据对
    window.update_amp_phase_pairs(test_pairs)
    
    # 显示演示说明
    def show_demo_info():
        QMessageBox.information(window, "数据对排序功能演示", 
            "欢迎使用数据对排序功能演示！\n\n"
            "功能说明：\n"
            "1. 启用拖拽排序：点击'启用拖拽排序'按钮，然后可以直接拖拽数据对重新排列\n"
            "2. 按钮排序：选择数据对后使用'↑ 上移'和'↓ 下移'按钮精确调整位置\n"
            "3. 重置顺序：点击'重置顺序'按钮可恢复数据对的原始排列顺序\n"
            "4. 顺序保持：排序后的顺序会在绘图时保持，确保数据对按期望顺序处理\n\n"
            "请尝试这些功能！")
    
    # 延迟显示说明
    QTimer.singleShot(500, show_demo_info)
    
    # 显示窗口
    window.show()
    
    return app.exec_()

if __name__ == "__main__":
    demo_sorting_features() 